﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models"  %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>

<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
    Trang chủ
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <div class="hoicho_content_mainleft col_left">
        <div class="hoicho_topbanner">
            <%
                AdvertHelper hAdvert = new AdvertHelper();
                Response.Write(hAdvert.showBanner(ViewData, 1));
            %>
        </div>
        <!-- Group san pam noi bat -->
      
     <div class="hoicho_group_product" >
        <div class="hoicho_top_groupproduct">
                  <div style="float:left">
            <p class="hoicho_texttop_product">
                Sản phẩm nổi bật</p>
                </div>
                 <div style="float:right;cursor:pointer" id="toggle"><img src="../Content/Images/collapse.png" width="20" height="20"/></div>
                  <div class="clr"></div>
        </div>
        <div class="hoicho_group_product_content" id="sanphamnoibat">
            <%
                NewsProductHelper.FetchProductResult lstHot = (NewsProductHelper.FetchProductResult)ViewData["HotProducts"];
                int i = 1;
                foreach (var hot in lstHot.products)
                {
                    if (i++ != 5)
                        Response.Write("<div class='hoicho_product_thumb'>");
                    else
                        Response.Write("<div class='hoicho_product_thumb reset_margin'>");
            %>
            <!-- Product thumb -->
            <center>
            <% 
                        
                string link = string.Format("<a href='{0}?prid={1}'>",
                                    Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(hot.NProTitle) }),
                                    hot.NProId
                                    );
            %>
            <%=link %>
            
            <img src="/../Content/Images/Upload/<%=(hot.NewsProductThumbs != null && hot.NewsProductThumbs.Count > 0 ? hot.NewsProductThumbs.First().NProThumbName : "" )%>"
                width="94" height="80" alt="" class="hoicho_img_productthumb" />
            </a>
            </center>
            <%-- <p class="font_bold" >--%>
            <%
                if (hot.NProTitle.Length > 40)
                {
                    Response.Write(string.Format("<p class='font_bold' title='{0}' >", hot.NProTitle));
                }
                else
                {
                   // Response.Write("<div style='height:36px !important'>");
                    Response.Write("<p class='font_bold' style='height:36px !important'>");
                }
            %>
            <%=link %>
            <%//Minh Thêm
/*-----------Truncate Product Title----------------*/
/*Thiết lập Title = 40 chars*/
if (hot.NProTitle.Length > 40)
{
    hot.NProTitle = hot.NProTitle.Substring(0, 37) + "...";
}
else
{
    int iCount = 40 - hot.NProTitle.Length;
    for (int k = 0; k < iCount; k++)
    {
        hot.NProTitle += " ";
    }
}
/*-----------End truncate Product Title*/ %>
            <%=hot.NProTitle %>
            </p>
           <%-- </div>--%>
             </a>
            <br />
            <p>
                <%
//Minh Thêm
/*-----------Truncate Product Provice Name----------------*/
/*Thiết lập Product Provice Name = 10 chars*/
//if (hot.Province.ProvName.Length > 10)
//{
//    hot.Province.ProvName = hot.Province.ProvName.Substring(0, 7) + "...";
//}
/*-----------End truncate Product Provice Name*/ %>
                Nơi rao:
                <%--<span class="hoicho_ograne_color">--%>
                <%if (hot.Province.ProvName.Length > 10)
                  {
                      Response.Write(String.Format("<span class='hoicho_ograne_color' title='{0}'>", hot.Province.ProvName));
                      hot.Province.ProvName = hot.Province.ProvName.Substring(0, 7) + "...";
                  }
                  else
                  {
                      Response.Write("<span class='hoicho_ograne_color'>");
                  } %>
                <%=hot.Province.ProvName%>
                <%Response.Write("</span"); %></p>
            <p>
                Ngày đăng: <span class="hoicho_ograne_color">
                    <%=hot.NProDate.ToString("dd/MM/yyyy") %></span></p>
            <div class="hoicho_bt_product_price">
                <%=(hot.NProPrice == null ? "Thương lượng" : hot.NProPrice.Value + " " + hot.NProPriceUnit) %></div>
            <p>
                <img src="/../Content/Images/hoicho_icon_view.gif" alt="" /><span class="hoicho_margin_leftright">Lượt
                    xem:</span><span class="hoicho_margin_leftright hoicho_ograne_color"><%=hot.NProViewCount %></span></p>
            <p>
                <img src="/../Content/Images/hoicho_icon_savenews.gif" alt="" class="hoicho_margin_leftright" /><a
                    href="#" class="SaveButton" onclick="SaveNews(<%=hot.NProId %>)" data-url='<%=hot.NProId %>'>Lưu tin</a></p>
            <%
Response.Write("</div>");
                }
            %>
            <!-- End Product thumb -->
  
        </div>
        <script type="text/javascript">
            $(".hoicho_group_product_content p[title]").tooltip();
            $(".hoicho_group_product_content span[title]").tooltip();
        </script>
    </div>
        <!-- End Group san pam noi bat -->
        <!-- Group san pham moi -->
        <div class="hoicho_group_product">
            <table width="100%" border="0">
                <tr>
                    <td colspan="2" class="hoicho_top_groupproduct">
                        <p class="hoicho_texttop_product">
                            Sản phẩm mới</p>
                    </td>
                    <td width="15%" align="left" bgcolor="#F5F7FB" class="hoicho_border_bottom">
                        <strong>Tỉnh/T.Phố</strong>
                    </td>
                    <td width="12%" align="right" bgcolor="#F5F7FB" class="hoicho_border_bottom" style="padding-right:20px">
                        <strong>Xem</strong>
                    </td>
                    <td width="4%" align="center" bgcolor="#F5F7FB" class="hoicho_border_bottom">
                        <strong>Ảnh</strong>
                    </td>
                </tr>
                <%
                    NewsProductHelper.FetchProductResult lstNew = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];
                    i = 0;
                    foreach (NewsProduct n in lstNew.products)
                    {
                        if (i % 2 == 0)
                            Response.Write("<tr bgcolor='#fafafa'>");
                        else
                            Response.Write("<tr bgcolor='#e0f0ff'>");
                        i++;
                        
                        string link = string.Format("<a href='{0}?prid={1}'>",
                                            Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }),
                                            n.NProId                                            
                                            );
                     %>
                    <td valign="top" >
                        <%=link %>
                            <img src="/../Content/Images/hoicho_arrow_newproduct.gif" alt="" />
                        </a>
                    </td>
                    <td valign="top">
                        <%=link %>
                            <%=n.NProTitle %></a>
                    </td>
                    <td valign="top">
                        <%=string.Format("<a href='{0}'>{1}</a>", n.Province.ProvId, n.Province.ProvName) %>
                        
                    </td valign="top">
                    <td align="right"  style="padding-right:20px">
                        <%=n.NProViewCount %>
                    </td>
                    <td valign="top">
                        <img src="/../Content/Images/Upload/<%=(n.NewsProductThumbs != null && n.NewsProductThumbs.Count > 0 ? n.NewsProductThumbs.First().NProThumbName : "" )%>" alt="" width="24" height="22" />
                    </td>
                <%
                        Response.Write("</tr>");
                    }
                         %>
            </table>
        </div>
    
        <!-- End Group san pham moi -->
        <!-- Group gian hang noi bat -->
        <div class="hoicho_group_product bg_reset">
            <div class="hoicho_top_groupproduct">
                <p class="hoicho_texttop_product col_left">
                    Gian hàng nổi bật</p>
                <div class="hoicho_member_all_comment col_right">
                    <span class="hoicho_margin_right">
                        <img src="/../Content/Images/arrow_number_news.gif" alt="" class="hoicho_margin_leftright" />
                        <span class="font_bold"><a href="#">Xem tất cả thành viên...</a></span> </span>
                    <%--<span class="hoicho_margin_right">
                        <img src="/../Content/Images/arrow_number_news.gif" alt="" class="hoicho_margin_leftright" />
                        <span class="font_bold"><a href="#">Xem thành viên thảo luận</a></span> </span>--%>
                </div>
            </div>
            <div class="hoicho_group_product_content">
            <table>
            <tr>
                <%
                    var lstHotMem = (List<Member>)ViewData["HotMember"];
                    int h = 0;
                    foreach (var hot in lstHotMem)
                    { 
                     %>
                     <td style="width:300px;">
                     <div style="float:left;width:70px">
                     <a href="<%=Url.RouteUrl("PrivateDefaultRoute", new { uid = hot.MemId, isEditMode = false }) %>">
                        <img src="/../Content/Images/Upload/<%=(hot.MemAvatar != null ? hot.MemAvatar : "" ) %>" width="70" height="70"
                             class="hoicho_feature_margin" style="border:1px solid #cbcbcb;padding:3px" />
                                  </div>
                                  <div style="float:right;">
                               <p>
                          
                              <%
                        Response.Write(string.Format("<a href='{0}'>", Url.RouteUrl("PrivateDefaultRoute", new { uid = hot.MemId, isEditMode = false })));
                     %>
                                <%=hot.MemUsername %>
                            </a></p>
                   <%--     <p class="font_bold">
                            <%
                        Response.Write(string.Format("<a href='{0}'>", Url.RouteUrl("PrivateDefaultRoute", new { uid = hot.MemId, isEditMode = false })));
                     %>
                                <%=(hot.MemCompany != null ? hot.MemCompany : string.Empty) %>
                            </a></p>--%>
                        <p class="hoicho_timer_rate">
                            Ngày tham gia: <span class="hoicho_ograne_color"><%=hot.MemJoinDate.ToString("dd/MM/yyyy") %></span></p>
                        <p class="hoicho_timer_rate">
                            Mobile: <span><%=hot.MemCellPhone %></span></p>
                        <p class="hoicho_timer_rate">
                            Ym: <span><a href="ymsgr:sendim?huynhlongho.cntt"><%=hot.MemYahoo %></a></span></p>
                      <%--  <p class="hoicho_timer_rate">
                            Email: <span><a href="#"><%=hot.MemEmail %></a></span></p>   --%>
                     </a>
                     </div>
                     <div class="clr"></div>
                     </td>
                <!-- Thumb feature product -->
          
                <!-- End Thumb feature product -->
                <%
                    h++;
                    if (h % 3 == 0)
                    {
                        %>
                        </tr>
                        <tr>
                        <%
                    }
                    }
                %>
                </tr>
                </table>
            </div>
        </div>
        <!-- End Group gian hang noi bat -->

        <div class="hoicho_topbanner">
            <%
                Response.Write(hAdvert.showBanner(ViewData, 2));
            %>
        </div>
        <!-- Group list menu -->
        <%
            List<PageType> pType = (List<PageType>)ViewData["MainMenu"];
            List<Category> cate; // = (List<Category>)ViewData["Categories"];
            int  perRow; // = (int)Math.Ceiling((double)cate.Count);
            int pC = 0;
            foreach (var page in pType)
            {
                pC++;
                if (page.PageUrl != null)
                    continue;
                cate = page.Categories.ToList();
        %>        
        <div class="hoicho_group_product">
            <div class="hoicho_header_feature">
                <ul>
                <%
                    i = 1;
                    foreach(Category c in cate)
                    {
                        //Response.Write(string.Format("<li class='page_{3} {0}'><a href='#' onclick='switchTab({3}, this); return false;' rel='cate_{2}' >{1}</a></li>", (i == 1 ? "selected_menu" : string.Empty), c.CateName, c.CateId, page.PageId));                        
                        Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a></li>",
                                                    (i==1 ? "selected_menu" : string.Empty),
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(page.PageName) }),
                                                    page.PageId,
                                                    c.CateId,
                                                    1,
                                                    NewsProductHelper.NEED_SELL,
                                                    1,
                                                    c.CateName));
                        i++;
                    }
                 %>
                </ul>
            </div>
            <div class="hoicho_feature_content">
                <div class="private_breakpage_replycoment col_left reset_margin">
                    <%
                        Response.Write(string.Format("<a href='{0}?pid={1}&cid=0&p=1&need={2}&prvid=1'>Cần bán</a> | <a href='{0}?pid={1}&cid=0&p=1&need={3}&prvid=1'>Cần mua</a>",
                                                        Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(page.PageName) }),
                                                        page.PageId,
                                                        NewsProductHelper.NEED_SELL,
                                                        NewsProductHelper.NEED_BUY));
                    %>
                </div>
                <div class="hoicho_select_province col_right">
                    <%
                        StringBuilder provLinks = new StringBuilder();
                        provLinks.Append("<a href='{0}?pid={1}&cid=0&p=1&need={2}&prvid=2'>Hà Nội</a> | ");
                        provLinks.Append("<a href='{0}?pid={1}&cid=0&p=1&need={2}&prvid=6'>Hải Phòng</a> | ");
                        provLinks.Append("<a href='{0}?pid={1}&cid=0&p=1&need={2}&prvid=3'>Hồ Chí Minh</a> | ");
                        provLinks.Append("<a href='{0}?pid={1}&cid=0&p=1&need={2}&prvid=5'>Đà Nẵng</a> |");
                        Response.Write(string.Format(provLinks.ToString(),
                                                Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(page.PageName) }),
                                                page.PageId,
                                                NewsProductHelper.NEED_SELL
                                                ));
                        %>
                            <select id="cbbProvince<%=pC %>" class="hoicho_input_select_province">
                            <%
                                string selected = "selected='selected'";
                                List<Province> provinces = (List<Province>)ViewData["Provinces"];
                                foreach(Province pr in provinces) {
                                    Response.Write(string.Format("<option value='{0}'>{1}</option>", 
                                                                pr.ProvId, 
                                                                pr.ProvName
                                                                ));
                                }
                            %>
                        </select>
                        <script type="text/javascript">
                            jQuery("#cbbProvince<%=pC %>").change(function () {
                                location.href=<%=string.Format("'{0}?pid={1}&cid=0&p=1&need={2}'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(page.PageName) }),
                                                    page.PageId,
                                                    NewsProductHelper.NEED_SELL
                                                    ) %> + '&prvid=' + jQuery(this).val();
                            });
                        </script>
                </div>
            </div>
            
                <%
                    int j = 1;
                    foreach (Category c in cate)
                    {
                        Response.Write(string.Format("<div id='cate_{1}' class='hoicho_group_listmenu_fation page_{2}' {0}>", (j>1 ? "style='display:none'" : string.Empty), c.CateId, page.PageId));
                        j++;
                        if (c.SubCategories == null)
                        {
                            Response.Write("</div>");
                            continue;
                        }
                        
                        //Số dòng mỗi cột
                        var subcategories = (from sub in c.SubCategories
                                            select new WebHoiChoMuaBan.Controllers.Helpers.CategoryHelper.SubCategory
                                            {
                                                id = sub.CateId,
                                                name = sub.CateName
                                            }).ToList();
                        perRow = (int)Math.Ceiling((double)subcategories.Count / 4);
                        
                        //4 cột subcategories
                        for (i = 0; i < 4; i++)
                        {
                            var subCate = (from sub in subcategories select sub).Skip(i).Take(perRow);
                            if (subCate != null)
                            {
                                Response.Write("<div class='private_menu_list_product'><ul>");
                                foreach (var s in subCate)
                                    Response.Write(string.Format("<li><img align='center' src='../Content/Images/bullet.jpg'><a href='{0}?pid={1}&cid={2}&p=1'>{3}</a></li>",
                                                                        Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(page.PageName) }),
                                                                        page.PageId,
                                                                        s.id,
                                                                        s.name));                                    
                                Response.Write("</ul></div>");
                            }
                        }
                        Response.Write("</div>");
                    }
                 %>
            
        </div>
        <%                
            } 
        %>
    </div>
</asp:Content>
